$:.unshift(File.expand_path(File.dirname(__FILE__)+"/../lib"))
$:.unshift(File.expand_path(File.dirname(__FILE__)+"/../ext"))

require "test/unit"
begin
    require 'statsample'
    HAS_SS=true
rescue
    HAS_SS=false
end

if(HAS_GSL.nil?)
begin
    require 'rbgsl'
    HAS_GSL=true
rescue
    HAS_GSL=false
end
end

require "alglib"
require 'matrix'
class TestAlglibCorrelationTests < Test::Unit::TestCase
    def test_pearson
      a=[2,3,4,5,6,7,8,9 ,10,22,20]
      b=[1,4,3,5,6,8,9,10,10,20,30]
      r=Alglib.pearson_correlation(a,b)
      t= Statsample::Bivariate.t_r(r, a.size)
      out  = Alglib.pearson_correlation_significance(r, a.size)
      assert_in_delta(out[:both], Statsample::Bivariate.prop_pearson(t,a.size), 0.0001)
      assert_in_delta(out[:left], Statsample::Bivariate.prop_pearson(t, a.size,:left), 0.0001)
      assert_in_delta(out[:right], Statsample::Bivariate.prop_pearson(t,a.size, :right), 0.0001)
    end
    def test_spearman
      a=[2,3,4,5,6,7,8,9 ,10,22,20]
      b=[1,4,3,5,6,8,9,10,10,20,30]
      r=Alglib.spearman_correlation(a,b)
      t= Statsample::Bivariate.t_r(r, a.size)
      out  = Alglib.spearman_correlation_significance(r, a.size)
      
      assert_in_delta(out[:both], Statsample::Bivariate.prop_pearson(t,a.size), 0.0001)
      assert_in_delta(out[:left], Statsample::Bivariate.prop_pearson(t, a.size,:left), 0.0001)
      assert_in_delta(out[:right], Statsample::Bivariate.prop_pearson(t,a.size, :right), 0.0001)
    end
end
